package com.sgcc.fj.pmos.e_fj_home.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.fj.pmos.e_fj_home.adapter.SDRYCLAdapter;
import com.sgcc.fj.pmos.e_fj_home.bean.SDRYCLBean;
import com.sgcc.fj.pmos.e_fj_home.contract.SDRYCLContract;
import com.sgcc.fj.pmos.e_fj_home.presenter.SDRYCLPresenter;


/**
 * 售电公司---------资产人员材料
 */
@Route(path = HomeArouterPath.HOME_SDRYCL)
public class SDRYCLActivity extends MvpBaseRecycleActivity<SDRYCLBean.DataBean.RyxxListBean, SDRYCLPresenter> implements SDRYCLContract.View {

    private String mOperateDate, mPublishType, mReadAmount;
    private String applyId = "", name = "";
    private TextView mTvFrom;
    private TextView mTvTime;
    private TextView mTvRange;
    private TextView mTvNumber;
    private SDRYCLAdapter mSDRYCLAdapter;

    @Override
    protected SDRYCLPresenter createPresenter() {
        return new SDRYCLPresenter();
    }

    @Override
    protected void receiveIntentExtras() {
        super.receiveIntentExtras();
        applyId = getIntent().getStringExtra("guid");
        name = getIntent().getStringExtra("sourceName");
        mOperateDate = getIntent().getStringExtra("operateDate");
        mPublishType = getIntent().getStringExtra("publishType");
        mReadAmount = getIntent().getStringExtra("readAmount");
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        if (!TextUtils.isEmpty(applyId)) {
            mPresenter.getData(applyId);
        }
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        mSDRYCLAdapter = new SDRYCLAdapter(mContext);

        View adapter_head_view = getLayoutInflater().inflate(R.layout.adapter_header_dcjzxx, null);
        mSDRYCLAdapter.addHeaderView(adapter_head_view);

        return mSDRYCLAdapter;
    }

    @Override
    public View getHeaderLayout(RelativeLayout parent) {
        View head_view = getLayoutInflater().inflate(R.layout.header_dcjzxx, parent, false);

        mTvFrom = (TextView) head_view.findViewById(R.id.tv_from);
        mTvTime = (TextView) head_view.findViewById(R.id.tv_time);
        mTvRange = (TextView) head_view.findViewById(R.id.tv_range);
        mTvNumber = (TextView) head_view.findViewById(R.id.tv_number);

        mTvFrom.setText(name);
        String time = "";
        try {
            time = StringUtils.isEmpty(DateUtils.getStrng_to_Times_ymdhms1(mOperateDate)) ?
                    DateUtils.get_TimesYMDHMSG1(mOperateDate) :
                    DateUtils.getStrng_to_Times_ymdhms1(mOperateDate);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        mTvTime.setText(time);
        mTvRange.setText(mPublishType);
        mTvNumber.setText(mReadAmount);

        return head_view;
    }

    @Override
    public String getTitleText() {
        return name + "资产人员材料";
    }

    @Override
    public void getDataSuccess(SDRYCLBean response) {
        if (response.getData() != null) {
            loadinglayout.showContent();
            if (response.getData().getRyxxList() != null) {
                loadSuccess(false, response.getData().getRyxxList());
            } else {
                loadinglayout.showEmpty();
            }
        } else {
            loadinglayout.showError();
        }
    }

    @Override
    public void getDataFailed() {

    }
}
